# -*- coding: utf-8 -*-
"""
@Time : 2024/10/28 21:05
@Author : ChenXiaoliang
@Email : middlegod@sina.com
@File : file_relation.py
"""
import os


def if_saved_in_file(text, file_path):
    if os.path.exists(file_path):
        # 如果text为空，默认返回True，表示已存在
        if not text:
            return True
        with open(file_path, 'r', encoding='utf-8') as f:
            content = f.read()
        return text in content
    else:
        with open(file_path, 'w', encoding='utf-8') as f:
            pass
        return False


def saved_to_file(text, file_path):
    with open(file_path, 'a', encoding='utf-8') as f:
        f.write(text + '\n')
